package cate.game.role.bag.prop.msg;

import cate.common.annotation.OperationSetter;
import cate.common.table.d.GDOperation;
import cate.game.GameBody;
import cate.game.client.ClientContext;
import cate.game.client.msg.ClientMsg;
import cate.game.client.msg.MsgConfig;
import cate.game.client.msg.MsgInput;
import cate.game.client.msg.id.MsgIdBBag;
import easy.java.dev.note.NoteField;

import java.util.ArrayList;
import java.util.List;

@ClientMsg(title = "使用 自选礼包 の 请求")
@OperationSetter(value = GDOperation.USE_PACK_CHOOSE, sub = "tid")
public class PropPackUseReq implements MsgInput {
    @NoteField(value = "礼包模板ID")
    public int tid;

    @NoteField(value = "选择哪几项", detail = "比如[0,2]就是选择其中的第一种和第三种")
    public List<Integer> indexes;

    @NoteField(value = "使用数量")
    public int num;

    @Override
    public void execute(GameBody game, ClientContext cc) {
        fix();
        cc.getRole().getBag().prop.usePack(indexes,tid,num);
    }

    public void fix() {
        if (this.num <= 0) {
            this.num = 1;
        }
        if (this.indexes == null) {
            this.indexes = new ArrayList<>();
        }
        if (this.indexes.isEmpty()) {
            this.indexes.add(0);
        }
    }

    @Override
    public MsgConfig conf() {
        return MsgIdBBag.PACK_USE_REQ;
    }
}
